﻿'#################################################################
'     Программа спроектирована и написана Чернявским Андреем
'              для курсовой работы по информатике,
'        весь код, от начала и до конца написан вручную.
' SVN проекта находится на http://code.google.com/p/testviewerbf/
'#################################################################
Public Class Testbox
    'Основные переменные.
    Public vopros As Integer = 1
    Dim setting As New My.MySettings
    Public bal As Integer = 0
    Public timer As Integer
    Public maxvopros As Integer
    'Переменные зачисления баллов.
    Public stroka(6) As String
    'Таймер.
    Dim sec As Integer
    Dim min As Integer
    Dim hou As Integer
    Dim bar As Integer
    Private Sub Testbox_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Загрузка из модуля.
        maximumvopros()
        vop1()
        'Шрифты
        Label1.Font = setting.Font1
        RadioButton1.Font = setting.Font2
        RadioButton2.Font = setting.Font2
        RadioButton3.Font = setting.Font2
        RadioButton4.Font = setting.Font2
        'Включение или выключение таймера.
        If timer = 1 Then
            Timer1.Enabled = True
            ProgressBar1.Visible = True
        Else
            Timer1.Enabled = False
            ProgressBar1.Visible = False
        End If
        'Присаивание таймера
        sec = setting.text23
        min = setting.text22
        hou = setting.text21
        'Processbar
        bar = ((setting.text21 * 60) + setting.text22) * 60 + setting.text23
        ProgressBar1.Maximum = bar
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        'Зачисление баллов.
        zach()
        'Счётчик вопросов.
        vopros = vopros + 1
        If vopros = (maxvopros + 1) Then
            EndForm.Visible = True
            Me.Close()
            GoTo 2
        End If
        'Загрузка vopX вопроса.
        Dim txt As String
        Dim ns As Integer = 0
        Dim FileNum As Short
        FileNum = FreeFile()
        If Module1.derictory = 0 Then
            FileOpen(FileNum, My.Application.Info.DirectoryPath & "\data\testbox\" & EnterForm.ComboBox1.Text & "\" & vopros & "", OpenMode.Input)
        Else
            FileOpen(FileNum, setting.der3 & "\data\testbox\" & EnterForm.ComboBox1.Text & "\" & vopros & "", OpenMode.Input)
        End If
        Do Until EOF(FileNum)
            txt = LineInput(FileNum)
            If ns = 6 Then
                ns = 0
                GoTo 1
            End If
            ns = ns + 1
            stroka(ns) = txt
            stroka(ns) = txt
            stroka(ns) = txt
            stroka(ns) = txt
            stroka(ns) = txt
            stroka(ns) = txt
        Loop
1:
        FileClose(FileNum)
        'Присваивание переменных.
        Label1.Text = stroka(1)
        RadioButton1.Text = stroka(2)
        RadioButton2.Text = stroka(3)
        RadioButton3.Text = stroka(4)
        RadioButton4.Text = stroka(5)

2:
    End Sub
    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        'Система таймера =).
        sec = sec - 1
        If sec = -1 Or sec < -1 Then
            min = min - 1
            sec = 59
        End If
        If min = -1 Or min < -1 Then
            hou = hou - 1
            min = 59
        End If
        If min <= 0 And sec <= 0 And hou <= 0 Or hou < 0 Then
            Timer1.Enabled = False
            EndForm.Visible = True
            Me.Visible = False
        End If
        Label2.Text = hou & ":" & min & ":" & sec
        'Progressbar
        If ProgressBar1.Value = ProgressBar1.Maximum Then
            GoTo 13
        Else
            ProgressBar1.Value = ProgressBar1.Value + 1
        End If
13:
        'colour timer
        If ProgressBar1.Value > ((ProgressBar1.Maximum / 2) + (ProgressBar1.Maximum / 4)) Then
            Label2.BackColor = Color.Red
        End If
    End Sub
End Class